package com.mmg.spzx.user.controller;

import com.mmg.spzx.model.entity.base.Region;
import com.mmg.spzx.model.entity.user.UserAddress;
import com.mmg.spzx.model.vo.common.Result;
import com.mmg.spzx.model.vo.common.ResultCodeEnum;
import com.mmg.spzx.user.service.UserAddressService;
import com.mmg.spzx.user.service.UserRegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户地址接口")
@RestController
@RequestMapping(value = "/api/user/userAddress")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @Operation(summary = "根据id获取用户地址")
    @GetMapping("/getUserAddress/{id}")
    public UserAddress getUserAddressById(@PathVariable Long id) {
        return userAddressService.getUserAddressById(id);
    }

    @Operation(summary = "修改收货地址")
    @PutMapping("/auth/updateById")
    public Result updateById(@RequestBody UserAddress userAddress) {
        userAddressService.updateById(userAddress);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "删除收货地址")
    @DeleteMapping("/auth/removeById/{id}")
    public Result removeById(@PathVariable Long id) {
        userAddressService.removeById(id);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "新增收货地址")
    @PostMapping("/auth/save")
    public Result save(@RequestBody UserAddress userAddress) {
        userAddressService.save(userAddress);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "获取用户地址列表")
    @GetMapping("/auth/findUserAddressList")
    public Result<List<UserAddress>> findUserAddressList() {
        List<UserAddress> list = userAddressService.findUserAddressList();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
